package com.tju.resource.oauth.controller.tb;

import cn.hutool.json.JSONObject;
import com.tju.resource.annotation.Log;
import com.tju.resource.model.TbMatlRev;
import com.tju.resource.business.tb_matl_rev.TbMatlRevService;
import com.tju.resource.result.Result;
import com.tju.resource.result.ResultEnum;
import com.tju.resource.result.ResultUtil;
import com.tju.resource.tool.enum_utils.FunctionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class TbMatlRevController {

    private final static String prefix = "matlrev";

    @Autowired
    TbMatlRevService service;
    @Log(type= FunctionType.List)
    @PostMapping(prefix + "/bymatl")
    @PreAuthorize("hasAuthority('sys:tool:matl:list')")
    public Result<Object> byMatl(@RequestBody Map<String, String> params) {
        return service.byPage(params);
    }

    @PostMapping(prefix + "/handle")
    @PreAuthorize("hasAuthority('sys:tool:matl:edit')")
    @Log(type= FunctionType.Modify)
    public Result<Object> handle(@RequestBody JSONObject rev) {
        return service.handle(rev);
    }

    @PostMapping(prefix + "/add")
    @PreAuthorize("hasAuthority('sys:tool:matl:add')")
    @Log(type= FunctionType.Add)
    public Result<Object> add(@RequestBody List<TbMatlRev> rev) {
//        return service.add(rev);
        System.out.println(rev);
        return ResultUtil.success(ResultEnum.SUCCESS, "got it!");
    }

    @PostMapping(prefix + "/upd")
    @PreAuthorize("hasAuthority('sys:tool:matl:edit')")
    @Log(type= FunctionType.Modify)
    public Result<Object> upd(@RequestBody TbMatlRev rev) {
        return service.add(rev);
    }

    @PostMapping(prefix + "/del")
    @PreAuthorize("hasAuthority('sys:tool:matl:delete')")
    @Log(type= FunctionType.Delete)
    public Result<Object> del(@RequestBody TbMatlRev rev) {
        return service.add(rev);
    }

}
